import { defineStore } from "pinia";
import {
  GetBaoHanZuHeXiangMuSel,
  GetJianSuoZuHeXiangMuSel,
  GetKeShiXinXiSel,
  GetMingXiXiangMuSel,
  GetShenQingDanSel,
  GetZuHeXiangMuSel
} from "@/api/modules/integratedProject";
// import piniaPersistConfig from "@/stores/helper/persist";

export const useIntegratedProject = defineStore({
  id: "integratedProject",
  state: () => ({
    // 科室的信息数据
    keShiOption: [] as any,
    // 科室id
    keShiId: "",
    // 左侧的申请单id
    shenQingDanID: "",
    // 中间的组合项目id
    zuHeXiangMuID: "",
    // 所属报告
    baoGao: "",
    // 申请单表格的数据
    shenQingDanOption: [] as any,
    // 组合项目表格的数据
    zuHeXiangMuOption: [] as any,
    // 组合项目搜索的表格的数据
    zuHeProjectSearch: [] as any,
    // 包含明细项目表格的数据
    baoHanMingXiOption: [] as any,
    // 包含组合项目查询
    baoHanZuHeOption: [] as any,
    // 右侧的tag点击是否请求
    tagIsChoose: false
  }),
  getters: {},
  actions: {
    getKeShiXinXiSel() {
      try {
        GetKeShiXinXiSel().then((res: any) => {
          if (res.Success === 0) {
            this.keShiOption = res.Data;
            this.keShiId = res.Data[0]?.KeShiID;
            this.setKeShiId(this.keShiId);
          }
        });
      } catch (e) {
        console.log(e);
      }
    },
    setKeShiId(id: string) {
      this.keShiId = id;
      this.getShenQingDanSel(id);
      this.getJianSuoZuHeXiangMuSel(id);
    },
    setShenQingDanID(id: string) {
      this.shenQingDanID = id;
    },
    setZuHeXiangMuIDID(id: string) {
      this.zuHeXiangMuID = id;
    },
    setBaoGao(type: string) {
      this.baoGao = type;
    },
    // 查询申请单的表格的数据
    getShenQingDanSel(id: any) {
      try {
        let obj = {
          strKeShiID: id
        };
        GetShenQingDanSel(obj).then((res: any) => {
          this.shenQingDanOption = res.Data;
        });
      } catch (e) {
        console.log(e);
      }
    },
    //   查询 组合项目
    async getZuHeXiangMuSel() {
      try {
        let obj = {
          strShenQingDanID: this.shenQingDanID,
          SuoShuBaoGaoFenLei: this.baoGao
        };
        await GetZuHeXiangMuSel(obj).then((res: any) => {
          this.zuHeXiangMuOption = res.Data;
        });
      } catch (e) {
        console.log(e);
      }
    },
    // setCurrent(tableRef: any, row?: any) {
    //   // 获取表格的方法 tableRef.value.getTableRef()
    //   const { setCurrentRow } = tableRef.value.getTableRef();
    //   setCurrentRow(row);
    // },
    //   查询 包含明细项目
    getBaoHanMingXiSel() {
      try {
        let obj = {
          strZuHeXiangMuID: this.zuHeXiangMuID
        };
        GetMingXiXiangMuSel(obj).then((res: any) => {
          this.baoHanMingXiOption = res.Data;
        });
      } catch (e) {
        console.log(e);
      }
    },
    //查询 包含组合项目
    getBaoHanZuHeXiangMuSel() {
      try {
        let obj = {
          strZuHeXiangMuID: this.zuHeXiangMuID
        };
        GetBaoHanZuHeXiangMuSel(obj).then((res: any) => {
          this.baoHanZuHeOption = res.Data;
        });
      } catch (e) {
        console.log(e);
      }
    },
    //   组合项目检索值查询
    // eslint-disable-next-line
    // @ts-ignore
    async getJianSuoZuHeXiangMuSel(id: any = this.keShiId as string): void {
      try {
        await GetJianSuoZuHeXiangMuSel(id).then((res: any) => {
          this.zuHeProjectSearch = res.Data;
        });
      } catch (e) {
        console.log(e);
      }
    },
    clearBaoHanMingXiOption() {
      this.baoHanMingXiOption = [];
    },
    clearBaoHanZuHeOption() {
      this.baoHanZuHeOption = [];
    },
    setTagRightData(data) {
      this.tagIsChoose = data;
    },
    clearZuHeXiangMuID() {
      this.zuHeXiangMuID = "";
    },
    clearShenQingDanID() {
      this.shenQingDanID = "";
    },
    // 清除所有的
    clearALL() {
      this.keShiOption = [];
      this.keShiId = "";
      this.shenQingDanID = "";
      this.zuHeXiangMuID = "";
      this.baoGao = "";
      this.shenQingDanOption = [];
      this.zuHeXiangMuOption = [];
      this.zuHeProjectSearch = [];
      this.baoHanMingXiOption = [];
      this.baoHanZuHeOption = [];
      this.tagIsChoose = false;
    }
  }
  // persist: piniaPersistConfig("geeker-integratedProject")
});
